home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_TEXT / Source / NeXTToCRLFText.m < prev    next >
Text File  |  1995-06-12  |  4KB  |  90 lines

  1. /***********************************************************************
  2. CRLF Converter class for Convert TEXT which converts between Mac and NeXT text.
  3. Copyright (C) 1993 David John Burrowes
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  8.  
  9. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  10.  
  11. The author, David John Burrowes, can be reached at:
  12.     davidjohn@kira.net.netcom.com
  13.     David John Burrowes
  14.     1926 Ivy #10
  15.     San Mateo, CA 94403-1367
  16. ***********************************************************************/
  17.  
  18. /*====================================================================
  19. This is the implementation file for the NeXTToCRLFText class.  Check the doc for NeXTToMacText.rtf to give you a suggestion of what this otherwise undocumented class is like..
  20.  
  21. NOTE: You may find that text doesn't line up properly unless you use the New Century Schoolbook Roman typeface, since this was created with it.
  22.  
  23. INFORMATION:
  24.     This is $Revision: 1.2 $ of this file
  25.     It was last modifiFed by $Author: death $ on $Date: 93/04/04 23:44:44 $
  26.      $Log:    NeXTToCRLFText.m,v $
  27. ====================================================================*/
  28.  
  29.  
  30. #import "NeXTToCRLFText.h"
  31. #import <memory.h>    // for memcpy
  32. #include <strings.h>
  33.  
  34.  
  35. @implementation NeXTToCRLFText
  36.  
  37.  
  38.  
  39.  
  40. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. //    Routine:        ConvertString:WithLength:
  42. //    Parameters:    a pointer to a string of data to be converted
  43. //                the length of the data the poiner poins to.
  44. //    Returns:        a poiner to a new block of data to be converted
  45. //    Stores:        the pointer we are returning
  46. //                the length of the new data
  47. //    Description:
  48. //        This takes the specified string, and copies it into a new buffer, 'converting' it as
  49. //        it goes.  This 'conversion' is actually pretty trivial.  If we find a LF, we write out
  50. //        a CRLF.  Otherwise we write out litterally.   Yawn.
  51. //    Bugs:
  52. //        we don't really check for errors anywhere (not taht there are many oportunities)...
  53. //    History
  54. //        93.07.05    djb    Created...
  55. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56. - (Pointer) ConvertString: (Pointer) theData WithLength: (Integer) length
  57. {
  58.     Character*    source = (Character*) theData; // getting a better typed ptr.
  59.     Integer        index;
  60.     PositiveInteger    destindex = 0;
  61.     Character*    dest = (Character*) NewPointer((length*2)+1); // worst case: every char  a LF, plus need room for final null
  62.     
  63.     [self    ResetResults];
  64.     
  65.     for (index = 0; index < length; index++)
  66.     {
  67.         if (source[index] == '\n')
  68.         {
  69.             dest[destindex] = '\r';
  70.             destindex++;
  71.         }
  72.         dest[destindex] = source[index];
  73.         destindex++;
  74.     }
  75.     //
  76.     //    Put a null on, just for the heck of it. 
  77.     //
  78.     dest[destindex] = EndOfCString;
  79.     //
  80.     //    Store the result, and return.  (note that destindex always ends up pointing to
  81.     //    the next byte to be used, and thus is also a count of the total number of bytes
  82.     //    in the dest string.
  83.     //
  84.     [self    StorePointer: dest];
  85.     [self    PutPositiveInteger: destindex Into: SECOND_RESULT];
  86.     [self    StoreErrorCode: errOK AndText: "Nothing could go wrong (pathetic program)!"];
  87.     return dest;
  88. }
  89. @end
  90.